package cn.com.eado.crm.m.db

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Entity(tableName = "cus_user")
@TypeConverters(CusUser.Converters::class)
data class CusUser(
    @PrimaryKey(autoGenerate = true)
    var id: Int,
    val total: Int,
    val rows: List<Row>
) {
    data class Row(
        val CUserID: String,
        val CUserName: String,
        val CompanyID: String,
        val CompanyName: String,
        val CreateDate: String,
        val DeptName: String,
        val Email: String,
        val Fax: String,
        val Fixed: String,
        val Mettle: String,
        val Mobile: String,
        val Position: String,
        val RoleName: String,
        val UpdateDate: String,
        val UserID: String,
        val UserName: String
    )

    class Converters{
        @TypeConverter
        fun stringToObject(value: String): List<Row> {
            val listType = object : TypeToken<List<Row>>() {
            }.type
            return Gson().fromJson(value, listType)
        }

        @TypeConverter
        fun objectToString(list: List<Row>): String {
            val gson = Gson()
            return gson.toJson(list)
        }
    }
}